import javafx.geometry.Pos;

import javax.swing.text.Position;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/23 16:55
 *  解读密码啊、
 *  走迷宫
 */
public class Day42 {
    static class Position {
        int x ;
        int y ;
        int steps;

        public Position(int x, int y, int steps) {
            this.x = x;
            this.y = y;
            this.steps = steps;
        }
    }
    //------------------------------------------
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String[] map = new String[10];
            for (int i = 0; i < 10; i++) {
                map[i] = scanner.next();
            }
            System.out.println(getShortPath(map,10,10));
        }
    }

    private static int getShortPath(String[] map, int m, int n) {
        int[][] direction = {{1,0},{0,-1},{0,1},{-1,0}};
        Queue<Position> positions = new LinkedList<>();

        Position position = new Position(0,1,0);
        Position out = new Position(9,8,0);

        positions.offer(position);
        boolean[][] flag = new boolean[m][n];
        while (!positions.isEmpty()){
            Position cur = positions.poll();
            flag[cur.x][cur.y] = true;
            if (cur.x == out.x && cur.y==out.y){
                return cur.steps;
            }
            for (int i = 0; i < direction.length; i++) {
                Position next = new Position(cur.x+direction[i][0],cur.y+direction[i][1],cur.steps+1);
                if (next.x>=0 && next.x<m&& next.y >= 0 && next.y<n && map[next.x].charAt(next.y)=='.'
                && !flag[next.x][next.y]){
                    positions.offer(next);
                }
            }
        }
        return 0;

    }


    //--------------------------------------------
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String str = scanner.nextLine();
            StringBuilder sb = new StringBuilder();
            char[] chars = str.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (chars[i]>='0' && chars[i]<='9' ){
                    sb.append(chars[i]);
                }
            }
            System.out.println(sb);
        }
    }
}
